const BASE_URL = "http://127.0.0.1:3000/api";

const request = {
  get: (url, params) => {
    const str = Object.keys(params).map(item => { // ["pageSize", "pageNum", "seachValue"]
      return item + "=" + params[item]  // ["pageSize=3","pageNum=1", "seachValue=''"]
    }).join("&") // "pageSize=3&pageNum=1&seachValue=''"

    return fetch(BASE_URL + url + "?" + str, {
      headers: {
        // 前端推荐在请求头里面传递token
        token: localStorage.getItem("token")
      }
    }).then(response => response.json())
  },
  post: (url, params) => {
    return fetch(BASE_URL + url, {
      method: "POST",
      body: JSON.stringify(params),
      headers: {"content-type": "application/json"}
    }).then(response => response.json())
  }
}